package pers.csw.lookBook.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.csw.lookBook.mapper.BooksMapper;
import pers.csw.lookBook.mapper.RecommendMapper;
import pers.csw.lookBook.dto.IndexDto;
import pers.csw.lookBook.entity.Books;
import pers.csw.lookBook.entity.Recommend;
import pers.csw.lookBook.service.RecommendService;

import java.util.ArrayList;
import java.util.List;

@Service
public class RecommendServiceImpl extends ServiceImpl<RecommendMapper,Recommend> implements RecommendService {

    @Autowired
    RecommendMapper recommendMapper;
    @Autowired
    BooksMapper booksMapper;

    @Override
    public List<IndexDto> getHome(){
        List<IndexDto> indexDtos = new ArrayList<>();
        recommendMapper.selectList(null).forEach(recommend -> {
            IndexDto i = new IndexDto();
            Books books = booksMapper.selectById(recommend.getBookId());
            i.setId(books.getId());
            i.setImg(books.getImg());
            i.setTitle(books.getTitle());
            i.setBookDsc(books.getBookDesc());
            i.setAuthor(books.getAuthor());
            i.setType(recommend.getType());
            i.setWord(books.getWord());
            indexDtos.add(i);
        });
        return indexDtos;
    }

}
